public class QuickSort  {
  private int[][] numbers;
  private int number;

  public void sort(int[][] values) {

    this.numbers = values;
    number = values.length;
    quicksort(0, number - 1);
  }

  private void quicksort(int low, int high) {
    int i = low, j = high;
   
    int[] pivot = numbers[low + (high-low)/2];

    while (i <= j) {
      while (numbers[i][0] < pivot[0]) {
        i++;
      }

      while (numbers[j][0] > pivot[0]) {
        j--;
      }

      if (i <= j) {
        swap(i, j);
        i++;
        j--;
      }
    }

    if (low < j)
      quicksort(low, j);
    if (i < high)
      quicksort(i, high);
  }

  private void swap(int i, int j) {
    int[] tmp = numbers[i];
    numbers[i] = numbers[j];
    numbers[j] = tmp;
  }
} 